classdef Track < handle
    
    properties
        % General variables
        name;
        fileName;
        volume;
        methodInd;
        methodSet; %Struct
        effect;
        effectInd;
        data; %midi or wav data
        
        % Signal variables
        Fs;
        x;
        y;
    end
    
    methods
        
        function obj = Track(nameIn, fileNameIn, dataIn, methodSetIn)
            obj.name = nameIn;
            obj.fileName = fileNameIn;
            obj.volume = 1;
            obj.methodInd = 1;
            obj.methodSet = methodSetIn;
            obj.effect = {};
            obj.effectInd = 1;
            obj.Fs = 44100;
            obj.data = dataIn;
            
            %obj.refresh();
        end
        
        function refresh(obj)
            %Si es midi
            if strcmp(obj.fileName(end-3:end), '.mid')
                obj.y = create_track(obj.data, obj.methodSet{obj.methodInd});
            else
                %obj.y = wavread(obj.fileName);
            end
            for k=1:length(obj.effect)
                switch obj.effect{k}.name
                    case 'Distortion'
                        obj.y = distortion(obj.Fs, obj.y, obj.effect{k}.drive, obj.effect{k}.tone);
                    case 'Flanger'
                        obj.y = flange(obj.Fs, obj.y, obj.effect{k}.variation, obj.effect{k}.rate);
                    case 'Delay'
                        disp('do Delay')
                    case 'Reverb'
                        obj.y = reverberation(obj.y, obj.effect{k}.impResp);
                end
            end
            
            obj.x = linspace(0, length(obj.y)/obj.Fs, length(obj.y));
        end
        
    end
end
    
    